
package nccloud.impl.arap.bill;

import nccloud.bs.arap.bill.aggbusi.ace.bp.GenVoucherBP;
import nccloud.impl.pub.ace.AceAggbusiEarningHVOPubServiceImpl;
import nccloud.itf.arap.bill.IEarninghvoMaintain;

import java.util.ArrayList;
import java.util.Map;

import org.apache.commons.collections4.map.HashedMap;

import antlr.collections.List;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.itf.gl.voucher.IVoucher;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.arap.earning.EarningBVO;
import nc.vo.arap.earning.EarningBillVO;
import nc.vo.arap.earning.EarningHVO;
import nc.vo.gl.pubvoucher.VoucherVO;
import nc.vo.gl.pubvoucher.DetailVO;
import nc.vo.gl.pubvoucher.OperationResultVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

public class EarninghvoMaintainImpl extends AceAggbusiEarningHVOPubServiceImpl implements IEarninghvoMaintain {

	private BaseDAO baseDAO;

	@Override
	public void delete(EarningBillVO[] clientFullVOs, EarningBillVO[] originBills) throws BusinessException {
		super.pubdeleteBills(clientFullVOs, originBills);
	}

	@Override
	public EarningBillVO[] insert(EarningBillVO[] clientFullVOs, EarningBillVO[] originBills) throws BusinessException {
		return super.pubinsertBills(clientFullVOs, originBills);
	}

	@Override
	public EarningBillVO[] update(EarningBillVO[] clientFullVOs, EarningBillVO[] originBills) throws BusinessException {
		return super.pubupdateBills(clientFullVOs, originBills);
	}

	@Override
	public EarningBillVO[] query(IQueryScheme queryScheme) throws BusinessException {
		return super.pubquerybills(queryScheme);
	}

	@Override
	public EarningBillVO[] save(EarningBillVO[] clientFullVOs, EarningBillVO[] originBills) throws BusinessException {
		return super.pubsendapprovebills(clientFullVOs, originBills);
	}

	@Override
	public EarningBillVO[] unsave(EarningBillVO[] clientFullVOs, EarningBillVO[] originBills) throws BusinessException {
		return super.pubunsendapprovebills(clientFullVOs, originBills);
	}

	@Override
	public EarningBillVO[] approve(EarningBillVO[] clientFullVOs, EarningBillVO[] originBills)
			throws BusinessException {
		return super.pubapprovebills(clientFullVOs, originBills);
	}

	@Override
	public EarningBillVO[] unapprove(EarningBillVO[] clientFullVOs, EarningBillVO[] originBills)
			throws BusinessException {
		return super.pubunapprovebills(clientFullVOs, originBills);
	}

	@Override
	public EarningBillVO genVoucher(String billid, String pzid) throws BusinessException {
		return new GenVoucherBP().gen(billid, pzid);
	}

	private String getAccountingbook(String sql) throws DAOException {

		baseDAO = new BaseDAO();
		String value = (String) baseDAO.executeQuery(sql, new ColumnProcessor());

		if (value == null) {
			value = "";
		}

		return value;
	}

	private ArrayList<String> getBaseDAO(String sql) throws DAOException {
		baseDAO = new BaseDAO();
		ArrayList<String> list = (ArrayList<String>) baseDAO.executeQuery(sql, new ColumnListProcessor());
		return list;
	}

	@Override
	public Map<String, String> getOrgMap(String orgid) throws BusinessException {
		String sqlaccountingbook = "select pk_accountingbook from org_accountingbook where dr=0 and accounttype=1 and pk_relorg='"
				+ orgid + "'";
		Map<String, String> map = new HashedMap<String, String>();
		if (orgid == null || orgid.equals("")) {
			map.put("accbook", "");
		} else {
			map.put("accbook", getAccountingbook(sqlaccountingbook));
		}

		return map;
	}

}
